package com.da.javatest.thread.juc.condition;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author chenlida
 * @date 2020/7/11 15:29
 * @description
 */
public class Condition2 {
    private static Lock lock = new ReentrantLock();
    private static Condition condition = lock.newCondition();

    public static class T1 extends Thread {
        @Override
        public void run() {
            lock.lock();
            try {
                condition.await();
            } catch (InterruptedException e) {
                System.out.println("中断标志：" + this.isInterrupted());
                e.printStackTrace();
            } finally {
                lock.unlock();
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        T1 t1 = new T1();
        t1.setName("t1");
        t1.start();
        TimeUnit.SECONDS.sleep(3);
        System.out.println("1.t1中断标志：" + t1.isInterrupted());
        t1.interrupt();
        System.out.println("2.t1中断标志：" + t1.isInterrupted());
    }
}
